package net.wesley.android;

import java.util.ArrayList;

import net.wesley.android.city.BeiJing;
import net.wesley.android.city.ChangSha;
import net.wesley.android.city.Changchun;
import net.wesley.android.city.ChengDu;
import net.wesley.android.city.Chongqing;
import net.wesley.android.city.DaLian;
import net.wesley.android.city.Dongguan;
import net.wesley.android.city.GuangZhou;
import net.wesley.android.city.Guiyang;
import net.wesley.android.city.HaErBin;
import net.wesley.android.city.HangZhou;
import net.wesley.android.city.Hefei;
import net.wesley.android.city.Huhehaote;
import net.wesley.android.city.Jiangmen;
import net.wesley.android.city.KunMing;
import net.wesley.android.city.Lanzhou;
import net.wesley.android.city.Lianyungang;
import net.wesley.android.city.NanJing;
import net.wesley.android.city.Nanning;
import net.wesley.android.city.Ningbo;
import net.wesley.android.city.Qingdao;
import net.wesley.android.city.ShangHai;
import net.wesley.android.city.Shantou;
import net.wesley.android.city.ShenYang;
import net.wesley.android.city.ShenZhen;
import net.wesley.android.city.ShiJiaZhuang;
import net.wesley.android.city.TaiYuan;
import net.wesley.android.city.TangShan;
import net.wesley.android.city.Wenzhou;
import net.wesley.android.city.WuHan;
import net.wesley.android.city.WuLuMuQi;
import net.wesley.android.city.XiAn;
import net.wesley.android.city.XiNing;
import net.wesley.android.city.XiaMen;
import net.wesley.android.city.Yantai;
import net.wesley.android.city.Yinchuan;
import net.wesley.android.city.ZhengZhou;
import net.wesley.android.city.ZhuHai;

public class CityManager {

	
	private static CityManager self=null;

	public static boolean isFinished(String chepai) {
		return get().checkFinished(chepai);
	}

	private ArrayList<City> cities=new ArrayList<City>();
	private ArrayList<City> wcities=new ArrayList<City>();

	private boolean checkFinished(String chepai) {
		for (int i=0;i<cities.size();i++){
			if (cities.get(i).match(chepai)){
				return true;
			}
		}
		return false;
	}

	CityManager(){
		//wcities.add(new HangZhou());
		//wcities.add(new Chongqing());
		//wcities.add(new Changchun());	
		//wcities.add(new Shantou());
		//wcities.add(new Jiangmen());
		
		cities.add(new Yinchuan());		
		cities.add(new Lianyungang());	
		cities.add(new Nanning());
		cities.add(new Wenzhou());
		cities.add(new Ningbo());
		cities.add(new Huhehaote());
		cities.add(new Yantai());
		cities.add(new Guiyang());
		cities.add(new Hefei());
		cities.add(new TangShan());		
		cities.add(new Lanzhou());		
		cities.add(new WuLuMuQi());		
		cities.add(new ZhuHai());
		cities.add(new ChangSha());
		cities.add(new XiaMen());		
		cities.add(new Dongguan());
		cities.add(new XiAn());
		cities.add(new ShangHai());
		cities.add(new Qingdao());
		cities.add(new KunMing());
		cities.add(new XiNing());
		cities.add(new NanJing());
		cities.add(new ShiJiaZhuang());
		cities.add(new TaiYuan());
		cities.add(new BeiJing());
		cities.add(new DaLian());
		cities.add(new ChengDu());
		cities.add(new GuangZhou());
		cities.add(new ShenYang());
		cities.add(new ShenZhen());
		cities.add(new HaErBin());
		cities.add(new WuHan());
		cities.add(new ZhengZhou());
	}
	
	private static CityManager get() {
		if (self==null){
			self=new CityManager();
		}
		return self;
	}

	public static boolean isFinishing(String chepai) {
		return get().checkFinishing(chepai);
	}

	private boolean checkFinishing(String chepai) {
		for (int i=0;i<wcities.size();i++){
			if (wcities.get(i).match(chepai)){
				return true;
			}
		}
		return false;
	}

	public static String[] getParamDesc(String chepai) {
		return get().paramDesc(chepai);
	}

	private String[] paramDesc(String chepai) {
		for (int i=0;i<wcities.size();i++){
			if (wcities.get(i).match(chepai)){
				return wcities.get(i).paramDesc();
			}
		}
		for (int i=0;i<cities.size();i++){
			if (cities.get(i).match(chepai)){
				return cities.get(i).paramDesc();
			}
		}
		return null;
	}

	public static City getCity(String chepai) {
		return get().getCityFromChepai(chepai);
	}

	private City getCityFromChepai(String chepai) {
		for (int i=0;i<cities.size();i++){
			if (cities.get(i).match(chepai)){
				return cities.get(i);
			}
		}
		return null;
	}

}
